/**
 * 
 */
package nguyen.hoan.sharelocation;

import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;

/**
 * @author Hoan Apr 7, 2014 2:11:51 PM
 * 
 */
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener {

	private SettingsFragment settingsFragment;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		settingsFragment = new SettingsFragment();
		getFragmentManager().beginTransaction().replace(android.R.id.content, settingsFragment).commit();
	}

	public static class SettingsFragment extends PreferenceFragment {

		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			addPreferencesFromResource(R.xml.settings);
		}
	}

	@Override
	public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {

		/*String locAutoUpdateKey = getResources().getString(R.string.settings_location_specifying_automatically_key);
		String locManualUpdateKey = getResources().getString(R.string.settings_location_specifying_manually_key);

		CheckBoxPreference locAutoUpdatePref = (CheckBoxPreference) settingsFragment.findPreference(locAutoUpdateKey);
		CheckBoxPreference locManualUpdatePref = (CheckBoxPreference) settingsFragment.findPreference(locManualUpdateKey);

		if (key.equals(locAutoUpdateKey)) {
			locManualUpdatePref.setChecked(!locAutoUpdatePref.isChecked());
		}
		if (key.equals(locManualUpdateKey)) {
			locAutoUpdatePref.setChecked(!locManualUpdatePref.isChecked());
		}*/

	}

	@Override
	protected void onResume() {
		super.onResume();
		SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
		prefs.registerOnSharedPreferenceChangeListener(this);
	}
}
